package org.exeed.controller;

import org.exeed.aop.tag.Auth;
import org.exeed.bean.ResultBean;
import org.exeed.entity.ContactEntity;
import org.exeed.entity.SubscribeEntity;
import org.exeed.service.ContactService;
import org.exeed.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/subscribe")
@RestController
public class SubscribeController {

    @Autowired
    private SubscribeService subscribeService;

    @PostMapping("/save")
    public ResultBean save(@RequestBody SubscribeEntity entity) {

        subscribeService.save(entity);

        return ResultBean.succeed();
    }

    @Auth
    @GetMapping("/selectPages")
    public ResultBean selectPages(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam(required = false, value = "key") String key) {
        return ResultBean.succeed(subscribeService.selectList(page, size, key));
    }

    @Auth
    @GetMapping("/getOneById")
    public ResultBean getOneById(@RequestParam("id") Long id) {
        return ResultBean.succeed(subscribeService.selectById(id));
    }

    @Auth
    @GetMapping("/delete")
    public ResultBean delete(@RequestParam("id") Long id) {
        subscribeService.delete(id);
        return ResultBean.succeed();
    }
}
